package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.QsQuestionDao;
import com.djinfo.work.entity.QsQuestionEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @date 2017-06-08 10:48:16
 */
@Repository("QsQuestionDao")
public class QsQuestionDaolmpl extends BaseDaoImpl implements QsQuestionDao {
    @Override
    public void saveOrUpdate(QsQuestionEntity object) {
        if(null==object.getId()){
            super.save(object);
        }else{
            super.update(object);
        }

    }

    @Override
    public List<QsQuestionEntity> page(String hql, Integer pageNum, Integer pageSize) {

        return (List<QsQuestionEntity>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public List<QsQuestionEntity> list(QsQuestionEntity object) {
        String hql="";
        if(object.getName()==null||"".equals(object.getName())){
            hql = " from QsQuestionEntity where 1=1";
        }else {
            hql = " from QsQuestionEntity where name like '%" + object.getName() + "%'";
        }
        return (List<QsQuestionEntity>)super.getList(hql);
    }

    @Override
    public Integer getAllRowCount(String hql) {

        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public void delete(QsQuestionEntity object) {
        super.delete(this.selectOne(object));
    }

    @Override
    public QsQuestionEntity selectOne(QsQuestionEntity object) {
        return (QsQuestionEntity)super.get(QsQuestionEntity.class,object.getId());
    }

    @Override
    public QsQuestionEntity getById(String id) {
        return (QsQuestionEntity)super.getByPrimaryKey(QsQuestionEntity.class, id);
    }
}
